/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GerenciarEquipamento.java
 *
 * Created on Jul 17, 2011, 2:17:45 AM
 */

package janelas;

import classes.Equipamento;
import db.EquipDAO;
import java.sql.SQLException;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import projetofinaltecnicas.Main;

/**
 * 
 * @author Vinicius
 */
public class GerenciarEquipamento extends javax.swing.JPanel {

    String[] headers = new String[3];

    String idioma;
    String usuario;
    /** Creates new form GerenciarEquipamento */
    public GerenciarEquipamento(String idioma, String usuario) {
        initComponents();

        this.idioma = idioma;
        this.usuario = usuario;

        internacionaliza();
        organizarHeaders();

        jiduser.setText(usuario);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popequip = new javax.swing.JPopupMenu();
        inserirEquip = new javax.swing.JMenuItem();
        editEquip = new javax.swing.JMenuItem();
        removeEquip = new javax.swing.JMenuItem();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelaequip = new javax.swing.JTable();
        titulo = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        juser = new javax.swing.JLabel();
        jiduser = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jInserir = new javax.swing.JButton();
        jEditar = new javax.swing.JButton();
        jRemover = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jNome = new javax.swing.JLabel();
        jId = new javax.swing.JLabel();
        jDesc = new javax.swing.JLabel();
        jIdEquip = new javax.swing.JTextField();
        jNomeEquip = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jDescEquip = new javax.swing.JTextPane();

        inserirEquip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/pencil.png"))); // NOI18N
        inserirEquip.setText("Inserir");
        inserirEquip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inserirEquipActionPerformed(evt);
            }
        });
        popequip.add(inserirEquip);

        editEquip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/pencil.png"))); // NOI18N
        editEquip.setText("Editar");
        editEquip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editEquipActionPerformed(evt);
            }
        });
        popequip.add(editEquip);

        removeEquip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/delete.png"))); // NOI18N
        removeEquip.setText("Remover");
        removeEquip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeEquipActionPerformed(evt);
            }
        });
        popequip.add(removeEquip);

        setMaximumSize(new java.awt.Dimension(776, 552));
        setPreferredSize(new java.awt.Dimension(776, 552));
        setSize(new java.awt.Dimension(776, 552));
        addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                formComponentAdded(evt);
            }
        });

        tabelaequip.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Nome", "Descrição"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaequip.getTableHeader().setReorderingAllowed(false);
        tabelaequip.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaequipMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tabelaequip);
        tabelaequip.getColumnModel().getColumn(0).setResizable(false);
        tabelaequip.getColumnModel().getColumn(1).setResizable(false);
        tabelaequip.getColumnModel().getColumn(2).setResizable(false);

        titulo.setFont(new java.awt.Font("Lucida Grande", 1, 13));
        titulo.setText("Gerenciar Equipamento");

        juser.setFont(new java.awt.Font("Lucida Grande", 1, 13));
        juser.setText("Usuário");

        jiduser.setText("ID User");

        jInserir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/pencil_add.png"))); // NOI18N
        jInserir.setText("Inserir");
        jInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jInserirActionPerformed(evt);
            }
        });

        jEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/pencil.png"))); // NOI18N
        jEditar.setText("Editar");
        jEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jEditarActionPerformed(evt);
            }
        });

        jRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/delete.png"))); // NOI18N
        jRemover.setText("Remover");
        jRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRemoverActionPerformed(evt);
            }
        });

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jNome.setText("Nome");

        jId.setText("ID Equipamento");

        jDesc.setText("Descrição");

        jScrollPane1.setViewportView(jDescEquip);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(titulo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 225, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(309, 309, 309)
                        .add(juser)
                        .add(18, 18, 18)
                        .add(jiduser))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(24, 24, 24)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jId)
                            .add(jDesc))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(layout.createSequentialGroup()
                                .add(jIdEquip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 72, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(18, 18, 18)
                                .add(jNome)
                                .add(18, 18, 18)
                                .add(jNomeEquip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 190, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jScrollPane1))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE)
                                .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(687, 687, 687))
                            .add(layout.createSequentialGroup()
                                .add(78, 78, 78)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jRemover, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                                    .add(jInserir, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jEditar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator2)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator1)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 732, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(titulo)
                    .add(juser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jiduser))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(jId)
                                    .add(jIdEquip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jNome)
                                    .add(jNomeEquip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(layout.createSequentialGroup()
                                        .add(34, 34, 34)
                                        .add(jDesc))))
                            .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 20, Short.MAX_VALUE)
                        .add(jInserir)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jEditar)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jRemover)
                        .add(20, 20, 20)))
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 300, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(47, 47, 47))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_formComponentAdded
        // TODO add your handling code here:

        tabelaequip.getColumnModel().getColumn(0).setPreferredWidth(5);
        tabelaequip.getColumnModel().getColumn(1).setPreferredWidth(50);
        tabelaequip.getColumnModel().getColumn(2).setPreferredWidth(480);

        jEditar.setEnabled(false);
        jRemover.setEnabled(false);
        jIdEquip.setEditable(false);

        int id;
        List<Equipamento> lista;

        jIdEquip.setText("-");

        try{
            EquipDAO equipd = new EquipDAO();

            lista = equipd.equipListar();

            preencherTabela(lista);
        }catch(SQLException e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_formComponentAdded

    private void jInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jInserirActionPerformed
        // TODO add your handling code here:
        String nome = jNomeEquip.getText();
        String desc = jDescEquip.getText();

        if(nome.equals("") || desc.equals("") || nome.length()>15 || desc.length()>75){
            if(idioma.equals("en_US")){
                JOptionPane.showMessageDialog(null, "All fields must be filled!", "ERROR!", JOptionPane.ERROR_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(null, "Todos os campos devem ser preenchidos!", "ERRO!", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            int j;
            
            if(idioma.equals("en_US")){
                Object[] options = {"Yes","No"};
                j = JOptionPane.showOptionDialog(null,
                                "Do you really want to insert this equipment?",
                                "Insert Equipment",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
            }
            else{
                Object[] options = {"Sim","Não"};
                j = JOptionPane.showOptionDialog(null,
                                "Deseja realmente inserir esse equipamento?",
                                "Inserir Equipamento",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
                }
            if (j==JOptionPane.YES_OPTION){
                Equipamento equip = new Equipamento();
                equip.setNome(nome);
                equip.setDescricao(desc);
                equip.setStatus("DISPONIVEL");

                try{
                    EquipDAO equipd = new EquipDAO();
                    List<Equipamento> lista;

                    equipd.inserirEquipamento(equip);
                    lista = equipd.equipListar();
                    preencherTabela(lista);

                    jIdEquip.setText("-");
                    jNomeEquip.setText("");
                    jDescEquip.setText("");
                    System.out.println("sala inserida com sucesso");
                    Main.log.info("O usuario: "+usuario+", inseriu um novo equipamento com sucesso!");
                }catch(SQLException e){
                    e.printStackTrace();
                    Main.log.severe("O usuario: "+usuario+", teve problemas ao tentar inserir um novo equipamento!");
                }
            }
        }
    }//GEN-LAST:event_jInserirActionPerformed

    private void tabelaequipMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaequipMouseClicked
        // TODO add your handling code here:

        if(evt.getButton() == java.awt.event.MouseEvent.BUTTON1 && evt.getClickCount() == 2){
            popequip.show(tabelaequip, evt.getX(), evt.getY());
        }
    }//GEN-LAST:event_tabelaequipMouseClicked

    private void editEquipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editEquipActionPerformed
        // TODO add your handling code here:

        jInserir.setEnabled(false);
        jEditar.setEnabled(true);
        jRemover.setEnabled(false);
        jDescEquip.setEditable(true);
        jNomeEquip.setEditable(true);

        int col = tabelaequip.getSelectedColumn();
        int lin = tabelaequip.getSelectedRow();

        int id = Integer.parseInt(tabelaequip.getValueAt(lin, 0).toString());

        try{
            EquipDAO equipd = new EquipDAO();
            List<Equipamento> lista;

            lista = equipd.equipListarRemover(id);

            jIdEquip.setText(""+id);
            jNomeEquip.setText(lista.get(0).getNome());
            jDescEquip.setText(lista.get(0).getDescricao());

        }catch(SQLException e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_editEquipActionPerformed

    private void removeEquipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeEquipActionPerformed
        // TODO add your handling code here:
        jInserir.setEnabled(false);
        jEditar.setEnabled(false);
        jRemover.setEnabled(true);

        int col = tabelaequip.getSelectedColumn();
        int lin = tabelaequip.getSelectedRow();

        int id = Integer.parseInt(tabelaequip.getValueAt(lin, 0).toString());

        try{
            EquipDAO equipd = new EquipDAO();
            List<Equipamento> lista;

            lista = equipd.equipListarRemover(id);

            jIdEquip.setText(""+id);
            jNomeEquip.setText(lista.get(0).getNome());
            jNomeEquip.setEditable(false);
            jDescEquip.setText(lista.get(0).getDescricao());
            jDescEquip.setEditable(false);

        }catch(SQLException e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_removeEquipActionPerformed

    private void inserirEquipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inserirEquipActionPerformed
        // TODO add your handling code here:
        jInserir.setEnabled(true);
        jEditar.setEnabled(false);
        jRemover.setEnabled(false);

        jNomeEquip.setEditable(true);
        jDescEquip.setEditable(true);

        List<Equipamento> lista;

        try{
            EquipDAO equipd = new EquipDAO();

            jIdEquip.setText("-");
            lista = equipd.equipListar();

            jNomeEquip.setText("");
            jDescEquip.setText("");

            preencherTabela(lista);
        }catch(SQLException e){
            e.printStackTrace();
        }

    }//GEN-LAST:event_inserirEquipActionPerformed

    private void jEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEditarActionPerformed
        // TODO add your handling code here:
        String nome = jNomeEquip.getText();
        String desc = jDescEquip.getText();
        
        int id = Integer.parseInt(jIdEquip.getText());
        if(nome.equals("") || desc.equals("") || nome.length()>15 || desc.length()>75){
            if(idioma.equals("en_US")){
                JOptionPane.showMessageDialog(null, "All fields must be filled!", "ERROR!", JOptionPane.ERROR_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(null, "Todos os campos devem ser preenchidos!", "ERRO!", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            int j;

            if(idioma.equals("en_US")){
                Object[] options = {"Yes","No"};
                j = JOptionPane.showOptionDialog(null,
                                "Do you really want to edit this equipment?",
                                "Edit Equipment",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
            }
            else{
                Object[] options = {"Sim","Não"};
                j = JOptionPane.showOptionDialog(null,
                                "Deseja realmente editar esse equipamento?",
                                "Editar Equipamento",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
                }
            if (j==JOptionPane.YES_OPTION){
                try{
                    EquipDAO equipd = new EquipDAO();
                    Equipamento equip = new Equipamento();
                    List<Equipamento> lista;

                    equip.setIdequip(id);
                    equip.setNome(nome);
                    equip.setDescricao(desc);

                    equipd.editarEquip(equip);

                    lista = equipd.equipListar();
                    preencherTabela(lista);
                    Main.log.info("O usuario: "+usuario+", editou com sucesso o equipamento: "+id);
                }catch(SQLException e){
                    e.printStackTrace();
                    Main.log.severe("O usuario: "+usuario+", teve problema e não conseguiu editar o equipamento: "+id);
                }
            }
        }
    }//GEN-LAST:event_jEditarActionPerformed

    private void jRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRemoverActionPerformed
        // TODO add your handling code here:

        int id = Integer.parseInt(jIdEquip.getText());

        int j;

        if(idioma.equals("en_US")){
            Object[] options = {"Yes","No"};
            j = JOptionPane.showOptionDialog(null,
                            "Do you really want to edit this equipment?",
                            "Edit Equipment",
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                            null,
                            options,
                            options[1]);
        }
        else{
            Object[] options = {"Sim","Não"};
            j = JOptionPane.showOptionDialog(null,
                            "Deseja realmente editar esse equipamento?",
                            "Editar Equipamento",
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                            null,
                            options,
                            options[1]);
            }
        if (j==JOptionPane.YES_OPTION){
            try{
                EquipDAO equipd = new EquipDAO();
                Equipamento equip = new Equipamento();
                List<Equipamento> lista;

                equip.setIdequip(id);

                equipd.removerEquip(equip);

                lista = equipd.equipListar();
                if(lista.isEmpty()){
                    jInserir.setEnabled(true);
                    jEditar.setEnabled(false);
                    jRemover.setEnabled(false);
                    jNomeEquip.setEditable(true);
                    jDescEquip.setEditable(true);
                    preencherTabela(lista);
                }else{
                    preencherTabela(lista);
                }

                jInserir.setEnabled(true);
                jEditar.setEnabled(false);
                jRemover.setEnabled(false);
                jNomeEquip.setEditable(true);
                jDescEquip.setEditable(true);
                jIdEquip.setText("-");
                jNomeEquip.setText("");
                jDescEquip.setText("");

                Main.log.info("O usuario: "+usuario+", removeu com sucesso o equipamento: "+id);
            }catch(SQLException e){
                e.printStackTrace();
                Main.log.severe("O usuario: "+usuario+", teve problemas e não conseguiu remover o equipamento: "+id);
            }
        }
    }//GEN-LAST:event_jRemoverActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem editEquip;
    private javax.swing.JMenuItem inserirEquip;
    private javax.swing.JLabel jDesc;
    private javax.swing.JTextPane jDescEquip;
    private javax.swing.JButton jEditar;
    private javax.swing.JLabel jId;
    private javax.swing.JTextField jIdEquip;
    private javax.swing.JButton jInserir;
    private javax.swing.JLabel jNome;
    private javax.swing.JTextField jNomeEquip;
    private javax.swing.JButton jRemover;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JLabel jiduser;
    private javax.swing.JLabel juser;
    private javax.swing.JPopupMenu popequip;
    private javax.swing.JMenuItem removeEquip;
    private javax.swing.JTable tabelaequip;
    private javax.swing.JLabel titulo;
    // End of variables declaration//GEN-END:variables

    public void preencherTabela(List<Equipamento> listaequip){

        DefaultTableModel tabela = (DefaultTableModel) tabelaequip.getModel();

        while (tabela.getRowCount() > 0) { //vai pegar todas as linha selecionadas maiores que zero, é vai remove-las!
            tabela.removeRow(0);
        }

        String[] linha = new String[]{null, null, null, null}; //colocando null em todas as colunas
        for (int i = 0; i < listaequip.size(); i++) {
            tabela.addRow(linha);
            tabela.setValueAt(listaequip.get(i).getIdequip(), i, 0);
            tabela.setValueAt(listaequip.get(i).getNome(), i, 1);
            tabela.setValueAt(listaequip.get(i).getDescricao(), i, 2);
        }

    }

    public void internacionaliza(){
        ResourceBundle palavras = ResourceBundle.getBundle("idiomas.Lingua_"+idioma);

        titulo.setText(palavras.getString("gerenciarEquip.titulo"));
        jId.setText(palavras.getString("gerenciarEquip.id"));
        headers[0] = palavras.getString("gerenciarEquip.id");
        jDesc.setText(palavras.getString("gerenciarEquip.desc"));
        headers[1] = palavras.getString("gerenciarEquip.desc");
        jNome.setText(palavras.getString("gerenciarEquip.nome"));
        headers[2] = palavras.getString("gerenciarEquip.nome");
        jInserir.setText(palavras.getString("gerenciarEquip.inserir"));
        jEditar.setText(palavras.getString("gerenciarEquip.editar"));
        jRemover.setText(palavras.getString("gerenciarEquip.remover"));
        juser.setText(palavras.getString("verificar.user"));
        inserirEquip.setText(palavras.getString("gerenciarEquip.inserir"));
        editEquip.setText(palavras.getString("gerenciarEquip.editar"));
        removeEquip.setText(palavras.getString("gerenciarEquip.remover"));
    }

    public void organizarHeaders(){
        for(int i=0;i<3;i++){
            tabelaequip.getTableHeader().setFont(new java.awt.Font(""+headers[i],java.awt.Font.PLAIN, 11));
            tabelaequip.getColumnModel().getColumn(i).setHeaderValue(""+headers[i]);
        }
    }
}
